<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html>
	<head>
		<title>Clothing Sales Inventory System--------Login</title>
		<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/resource/form.css">
	</head>
	<body>
		<jsp:include page="/common.jsp"/>
		<center>
		<table align="center" cellpadding="3" cellspacing="0" width="400px" style="border:1px gray solid;">
		<tbody>
			<tr>
				<td colspan="2" align="center">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;服装进销系统登录</td>
			</tr>
			<tr>
				<td width="35%" align="right">用户名</td>
				<td><input type="text" name="userName"></td>
			</tr>
			<tr>
				<td align="right">口&nbsp;&nbsp;&nbsp;&nbsp;令</td>
				<td><input type="password" name="passWord"></td>
			</tr>
			<tr>
				<td align="right" >验证码</td>
				<td><input style="width:120px" type="text" name="code"><img id="valImg" src="${pageContext.request.contextPath}/system/user/genValImage.htm" alt="单击刷新"></td>
			</tr>
			<tr>
				<td></td>
				<td><input type="submit" class="btnOk" value="确定" onclick="login();"></td>
			</tr>
		</tbody>
		</table>
		</center>
		<script>
		
		 
			$(function() {
				$('#valImg').click(
						function() {//生成验证码  
							$(this).hide().attr(
									'src',
									'${pageContext.request.contextPath}/system/user/genValImage.htm?'
											+ Math.floor(Math.random() * 100))
									.fadeIn();
						})
			});

			document.all("userName").focus();
			function login() {
				var username = document.all("userName").value;
				var password = document.all("passWord").value;
				var valcode = document.all("code").value;
				var url = "${pageContext.request.contextPath}/system/user/login.htm?userName="
						+ username
						+ "&passWord="
						+ password
						+ "&code="
						+ valcode;
				$.get(
								url,
								function(response) {
									rst = response;

									switch (rst) {
									case '0':
										alert("请输入用户名|口令|验证码");
										break;
									case '1':
										window.location.href = "${pageContext.request.contextPath}/security/role/toMain.htm";
										break;
									case '-1':
										alert("没有找到用户-[" + username + "]");
										break;
									case '-2':
										alert("验证码错误-[" + valcode + "]");
										break;
									default:
										alert("未知错误-[" + rst + "]");
										break;
									}

								});
			}
		</script>
	</body>
</html>